(function($){
	$(window).load(function(){
		
	//comment上滑动显示 回复、点赞
//	$(".com").mouseover(function(){
//		console.log("a");
//		//$(".com .show a").css("display","inline-block");
//	}).mouseout(function(){
//		console.log("b");
//		//$(".com .show a").css("display","none");
//	});
	var index=0;
	ajax(index);

		
	$("#pre").css("display","none");
	$(".page .num").eq(0).addClass("active").mousemove(function(){
		
		$(this).addClass("hot");
	})
	
	$(".page .num").click(function(){
		 index = $(this).index()-1;
		$(".page .num").removeClass().each(function(){
			$(this).addClass("num");
		})
		$(this).addClass("active").addClass("hot");
		$("#pre").css("display","inline-block")
		if(index == 0){
			$(this).addClass("active").addClass("hot");
			$("#pre").css("display","none")
		}
		ajax(index);
		
	})
	$("#pre").click(function(){
		index--
		if(index<0){
			index = 2;
		}
		
		$(".page .num").removeClass().each(function(){
			$(this).addClass("num");
		})
		$(".page .num").eq(index).addClass("active").addClass("hot");
		$("#pre").css("display","inline-block")
		if(index == 0){
			$(".page .num").eq(index).addClass("active").addClass("hot");
			$("#pre").css("display","none")
		}
		
		
		
		
		ajax(index);
	})
	$("#next").click(function(){
		index++
		if(index==2){
			index = 0;
		}
		
		$(".page .num").removeClass().each(function(){
			$(this).addClass("num");
		})
		$(".page .num").eq(index).addClass("active").addClass("hot");
		$("#pre").css("display","inline-block")
		if(index == 0){
			$(".page .num").eq(index).addClass("active").addClass("hot");
			$("#pre").css("display","none")
		}
		
		
		
		
		
		ajax(index);
	})
	

	function zenjia(arr,j){
		if(j>=5){
			return arr;
		}else{
			for(j;j<5;j++){
				arr.push({name:""});
			}
			return arr;
		}	
	}
	
	function Image(arr1,k){
		var vhtml = "";
		if(k==0){
			return vhtml;
		}else{
			for(var j=0;j<k;j++){
				
				vhtml+="<div><img src='https:"+arr1[j].imgUrl+"'/></div>"
			}
			return vhtml;
		}	
	}
	
	
	function ajax(index){
		$.ajax({
			url: 'https://sclub.jd.com/productpage/p-1024223206-s-0-t-5-p-'+index+'.html?',
			jsonp: 'callback',
			dataType: 'jsonp',
			success: function (data) {
				//console.log(data);
				var sHtml = '';
				var data1 = data.comments;
				console.log(data1);
				
			data1.forEach(function(v,i){
				//console.log(data1[]);
				var x ,arr=[],y,arr1=[];
				if(!data1[i].commentTags){
					x=0;
					data1[i].commentTags =[];
				}else{
					x = data1[i].commentTags.length;
				}
				 arr = data1[i].commentTags;
				 
				if(!data1[i].userClientShow){
					data1[i].userClientShow="";
				}else{
					
				}
				if(!data1[i].images){
					y=0;
					data1[i].images =[];
				}else{
					y = data1[i].images.length;
				}
				
				var vhtml = Image(data1[i].images,y);
				console.log(vhtml);
				data1[i].commentTags = zenjia(arr,x);
				 //console.log(data1[i].referenceTime.slice(0,16));
				//console.log(data1[i].commentTags[0].name);
				sHtml += "<div class='com'>"
				sHtml +="<div class='com1'>"
				sHtml +="	<div class='div1'></div>"
				sHtml +="	<div class='div2'>收货"+data1[i].days+"天后评论</div>"
				sHtml +="	<div class='div2'>"+data1[i].referenceTime.slice(0,16)+"</div>"
				sHtml +="	<div class='div3'>"
				sHtml +="	<ul>"
				sHtml +="			<li>"+data1[i].productColor+"</li>"
				sHtml +="			<li>"+data1[i].productSize+"</li>"
				sHtml +="		</ul>"
				sHtml +="	</div>"
				sHtml +="</div>"
				sHtml +="<div class='text'>"
				sHtml +="		<div class='leibie'>"
				sHtml +="			<em>"+data1[i].commentTags[0].name+"</em>"
				sHtml +="			<em>"+data1[i].commentTags[1].name+"</em>"
				sHtml +="			<em>"+data1[i].commentTags[2].name+"</em>"
				sHtml +="			<em>"+data1[i].commentTags[3].name+"</em>"
				sHtml +="			<em>"+data1[i].commentTags[4].name+"</em>"
				sHtml +="		</div>"
				sHtml +="	<p>"
				sHtml +=		data1[i].content
				sHtml +="</p>"
				sHtml +="	<div class='showimg'>"
				sHtml += vhtml
				sHtml +="	</div>"
				sHtml +="	<div class='show'>"
				sHtml +="		<a href='javascript:;'>点赞（0）</a>"
				sHtml +="		<a href='javascript:;'>回复（0）</a>"
				sHtml +="	</div>	"
				sHtml +="</div>"
				sHtml +="<div class='comright'>"
				sHtml +="	<div class='comrighttop'>"
				sHtml +="		<img src=https://"+data1[i].userImage+" />"
				sHtml +="		<div>"+data1[i].nickname+"</div>"
				sHtml +="	</div>"
				sHtml +="	<div class='comrightcen'>"
				sHtml +="		<span style='color:#ff0000'>"+data1[i].userLevelName+"</span>"
				sHtml +="		<span>"+data1[i].userProvince+"</span>"
				sHtml +="	</div>"
				sHtml +="	<div class='comrightbut'>"
				sHtml +="		<span>"
				sHtml +=	data1[i].userClientShow
				sHtml +="		</span>"
				sHtml +="	</div>"
				sHtml +="</div>"
				sHtml +="</div>";
			})
			
			$("#charu").html(sHtml);	
				
				$("#charu .com").mouseover(function(){
					//console.log("a");
				 
				$(this).find(".show a").css("display","inline-block");
				}).mouseout(function(){
					//console.log("b");
				$(this).find(".show a").css("display","none");
				});		
				
			}
					
			});
	}
	
	
	
	
})	
})(jQuery)



















